<template>
	<view class="container">
		<uni-forms ref="form" :rules="{}">
			<uni-forms-item label="用户名:" name="">
				<uni-easyinput @change="Changeusername" v-model="user.username" placeholder="请输入用户名" />
			</uni-forms-item>
			<uni-forms-item label="密码:" name="">
				<uni-easyinput type="password" v-model="user.password" placeholder="请输入密码" />
			</uni-forms-item>
			<uni-forms-item label="学院" name="">
				<uni-combox :candidates="user.colleges" v-model="user.college" placeholder="请选择学院"></uni-combox>
			</uni-forms-item>
			<uni-forms-item label="专业" name="">
				<uni-combox :candidates="user.majors" v-model="user.major" placeholder="请选择专业"></uni-combox>
			</uni-forms-item>
			<uni-forms-item label="姓名:" name="">
				<uni-easyinput @change="Changename" v-model="user.name" placeholder="请输入姓名" />
			</uni-forms-item>
			<uni-forms-item label="电话:" name="">
				<uni-easyinput @change="Changephone" v-model="user.phone" placeholder="请输入电话" />
			</uni-forms-item>
			<uni-forms-item label="邮箱:" name="">
				<uni-easyinput @change="Changeemail" v-model="user.email" placeholder="请输入邮箱" />
			</uni-forms-item>
			<uni-forms-item label="" name="">
				<button type="primary" @click="register">注册</button>
			</uni-forms-item>
		</uni-forms>
	</view>

</template>

<script>
	export default {
		data() {
			return {
				user: {
					username: '',
					password: '',
					college: '',
					colleges: ['信息工程学院'],
					major: '',
					majors: ['移动应用'],
					phone: '',
					fullname: '',
					email: ''
				}
			}
		},
		methods: {
			Changeusername(e) {
				console.log(e);
			},
			Changephone(e) {
				console.log(e);
			},
			Changeemail(e) {
				console.log(e);
			},
			Changename(e) {
				console.log(e);
			},
			register(e) {
				uni.request({
					url: 'http://localhost:8090/freshmenapp/user/register',
					method: 'post',
					data: this.user,
					success: res => {
						if (res.data.success) {
							console.log(res.data);
							uni.showToast({
								title: `恭喜${this.user.username}注册成功`,
								duration: 3000000
							})
						} else {
							uni.showToast({
								title: '注册失败',
								icon: 'none'
							})
						}

					},
					fail: (error) => {
						console.error('请求失败:', error);
						uni.showToast({
							title: '网络请求失败，请重试',
							icon: 'none'
						});
					},
					complete: () => {}
				});
			}
		},
		onLoad: () => {
			uni.onTabBarMidButtonTap(function(e) {
				console.log(e)

			})
		}
	}
</script>

<style>
	.container {
		margin: 20px;
	}
</style>